<?php
// ************************************************************************
// created on 10/04/2003, created by S.Gnanavel
// Purpose:
//	This file contains classes to generate master menu and
//	sub menu.
// ************************************************************************


// ************************************************************************
// This class contains functions to generate master menu and
// sub menu.
// ************************************************************************
class cMenu
	{
	// ************************************************************************
	// declarations
	// ************************************************************************
	var $menu_name;
	var $file_name;
	var $main_menu;
	var $sub_menu;

	// ************************************************************************
	// This functions get menu_array as input which is in the
	// format:
	//	" menu_array[menu_id][file_id][privilege_desc]=permission"
	// It checks each value of the above array for privilege, if
	// permission exist then menu is generated in the following format
	// format:
	//	"$menu[menu_name]=file_name"
	// ************************************************************************
	function getMenu($menu_array)
		{
		$member_id=$_SESSION["gmember_id"];
		// ************************************************************************
		// get the privilege portion from the gprivilege array (which is
		// stored in session)
		// ************************************************************************
		$user_privilege=$_SESSION[gprivilege][$member_id];
		// ************************************************************************
		// The menu_array is splitted into menu_id and file_array.
		// Format of file_array:
		//	permitted_file_array[file_id]=array(privilege_desc=>permission)
		// ************************************************************************
		if($menu_array)
			{
			foreach($menu_array as $menu_id=>$permitted_file_array)
				{
				// ************************************************************************
				// The file_array is splitted into file_id and $privilege array.
				// Format of $privilege array:
				//	privilege[privilege_desc]=permission
				// ************************************************************************
				if($permitted_file_array)
					{
					foreach($permitted_file_array as $file_id=>$privilege)
						{
						// ************************************************************************
						//  The user_privilege array obtained from gprivilege array
						// is splitted into privilege_desc and permission
						// ************************************************************************
						if($user_privilege)
							{
							foreach($user_privilege as $privilege_desc=>$permission)
								{
								// **************************************************************************
								// if privilege exists for the menu item then menu array is generated.
								// **************************************************************************
								if ( strcmp($privilege_desc,key($privilege)) == 0 && strchr($permission,current($privilege)) )
									{
									$menu_name1=$this->menu_name[$menu_id];
									$file_name1=$this->file_name[$file_id];
									$menu[$menu_name1]=$file_name1;
									}
								}	
							}
						}
					}	
				}
			return $menu;	
			}
		}	

	// ************************************************************************
	// This function sends main_menu array from child class as
	// argument to getMenu function to generate master menu.
	// ************************************************************************
	function getMasterMenu()
		{
		return $this->getMenu($this->main_menu);
		}

	// ************************************************************************
	// This function send the sub_menu array from child class as
	// argument to getMenu function to generate sub menu.
	// ************************************************************************
	function getSubMenu($main_menu_id)
		{
		return $this->getMenu($this->sub_menu[$main_menu_id]);
		}
	}


?>
